#include <vector>
#include "cell.h"

/**
*    All objects in game are contained within a Cell, a Cell has a position, called it's Loc
*    All Cells are adjacent to 8 other Cells those Cells are contained in the Adj array of Cells
*    If a Cell is in a corner then the Cell in the Adj for that corner is itself
*    Adj[0] = NW, Adj[1] = N, Adj[2] = NE
*    Adj[3] = W,  Adj[4] = C, Adj[5] = E
*    Adj[6] = SW, Adj[7] = S, Adj[8] = SE
*
*/

          

void Cell::setAdj(Cell* otherCell, int i){Adj[i] = otherCell;}
Cell* Cell::getAdj(int i){return(Adj[i]);}
bool Cell::isSolid(){return solid;}

bool Cell::isAdj(Cell* otherCell)
{
   for(int i = 0; i < 8; i++)
   {
        if(Adj[i] == otherCell)
             return true;
   }
   return false;
}


std::string Cell::view()
{
   std::string msg;
   if(Contents.empty())
   {
        msg+="nothing.\n";
   }else{
        for(unsigned int it = 0;it < Contents.size(); it++)
        {
             if(Contents.at(it)->getDesc() != "")
                  msg += Contents.at(it)->getDesc();
                  msg += "\n";
        }
        
   }
   return(msg);
}

int Cell::getX(){return Loc.x;}
int Cell::getY(){return Loc.y;}
pos Cell::getLoc(){return Loc;}

bool Cell::isCloser(Cell* toCell, Cell* thanCell)
{
   int MyxDif = Loc.x - toCell->getX();
   int MyyDif = Loc.y - toCell->getY();
   int MyTotal = MyxDif + MyyDif;

   int txDif = thanCell->getX() - toCell->getX();
   int tyDif = thanCell->getY() - toCell->getY();
   int tTotal = txDif + tyDif;

   return((MyTotal <= tTotal)?true:false); 
}    

